//
//  SearchView.m
//  AmountBody
//
//  Created by smm on 2018/1/4.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "SearchView.h"
#import "Masonry.h"
@implementation SearchView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setupViews];
    }
    return self;
}

-(void)setupViews{
    
    self.s_textField = [[UITextField alloc]init];
    [self addSubview:self.s_textField];
    self.s_image = [[UIImageView alloc]init];
    [self addSubview:self.s_image];
    self.lineView = [[UIView alloc]init];
    [self addSubview:self.lineView];
    self.s_textField.textColor = QianZi_color;
    self.s_textField.placeholder = @"输入面料号进行筛选";
    self.s_textField.font = Cell_Medium_Font;
    self.s_textField.returnKeyType = UIReturnKeySearch;
    self.s_textField.delegate = self;
    self.lineView.backgroundColor = Line_color;
    
    [self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.right.bottom.equalTo(self);
        make.width.equalTo(self).multipliedBy(0.6);
        make.height.mas_equalTo(1);
        
    }];
    self.s_image.image = [UIImage imageNamed:@"search2"];
    [self.s_image mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.bottom.equalTo(self).with.offset(-10);
        make.right.equalTo(self);
        make.width.mas_equalTo(20);
        
    }];
    [self.s_textField mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.bottom.equalTo(self).with.offset(-10);
        make.right.equalTo(self.s_image).with.offset(-5);
        make.width.equalTo(self).multipliedBy(0.5);
        
    }];
}
static TextFieldBlock _textBlock;
+(void)blockForTextField:(TextFieldBlock)textBlock
{
    _textBlock = textBlock;
}
#pragma mark - textFeildDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (_textBlock) {
        _textBlock(textField.text);
    }
    return YES;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

{
    
    return YES;
    
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    
}

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    return YES;
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
    if (_textBlock) {
        _textBlock(textField.text);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
